﻿Imports Training.Common

Partial Public Class ChangeGroupPassword
    Inherits System.Web.UI.Page
    Public gName As String ' group name
    Dim gid As Integer

    ''' <summary>
    ''' Page Load event, check for querystring data and assign to variables
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for querystring data
        If IsNothing(Request.QueryString("gid")) Or IsNothing(Request.QueryString("nm")) Then
            Response.Redirect("Groups.aspx")
        Else
            gid = Request.QueryString("gid")
            gName = Request.QueryString("nm")
        End If
    End Sub

    ''' <summary>
    ''' Change Password button click event, call function to change password
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>boolen return values determines success</remarks>
    Private Sub btnChangePass_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChangePass.Click
        ' get loginname
        Dim lName As String
        lName = GetGroupLogin(gid)

        ' check for validation
        If Page.IsValid Then
            If ChangeMembershipPassword(lName, tbPass.Text) Then
                lblResponse.Text = "Password for " & gName & " has been changed"
            Else
                lblResponse.Text = "An error occurred on password change. Error has been logged.<br />Technical support has been alerted."
            End If
        Else
            lblResponse.Text = "<b>There was a problem validating the form. Please try again.</b>"
        End If
    End Sub
End Class